{% extends "automan/template.html" %}
{% load staticfiles %}
{% block title %}组件列表{% endblock %}

{% block content %}
<div>
    <span class="select-box inline r">
        {% include "automan/filter.html" %}
        <button type="submit" class="btn btn-success filter_btn" >过滤</button>
        {% include "automan/search.html" %}
    </span>
</div><br/><br/>

<table class="table table-border table-bordered table-bg">
    <thead>
        <th>APP名称</th>
        <th>管理员</th>
        <th>描述说明</th>
        <th>操作</th>
        <th>更新时间</th>
    </thead>
    <tbody>
        {% for item in object_list %}
        <tr class="text-l">
            <td>
                <span>{{ item.name }}</span>
            </td>
            <td>{{ item.manage_user }}</td>
            <td>{{ item.description }}</td>
            <td>
                {% for env in env_name %}
                <a href="{% url 'deploy:operate_app' app_name=item.id env=env.id %}">
                    <button id="operateBtn" class="btn btn-primary-outline radius">{{ env }}</button>
                </a>
                {% endfor %}
            </td>
            <td>{{ item.change_date }}</td>
        </tr>
        {% endfor %}
    </tbody>
</table>
<br/>
{#分页    #}
{% include "automan/paginate.html" %}
{% endblock %}

{% block script %}
<script>
$(".search_btn").click(function () {
    var search_pk = $("input[name='search_pk']").val() || "demo";
    if (search_pk == "demo") {
        $("body").Huimodalalert({content: "<span class='c-error'>请输入关键字再进行搜索!", speed: 3000});
        return false;
    }
    search_pk = search_pk.replace(/(^\s*)|(\s*$)/g, "");
    var url = "{% url 'deploy:operate' %}?search_pk=" + search_pk;
    console.log(url);
    location.href = url;
});
$(".filter_btn").click(function () {
    var filter_app_name = $("select[name='app_name']").val();
    console.log(filter_app_name);
    if (filter_app_name.length == 0) {
        $("body").Huimodalalert({content: "<span class='c-error'>请选择组件再过滤！</span>", speed: 3000});
        return false;
    } else {
        var url = "{% url 'deploy:operate' %}?app_name=" + filter_app_name;
    }
    console.log(url);
    location.href = url;
});
</script>
{% endblock %}